package com.tujia.lambda;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class MyLambda {
    public static void main(String[] args) {
        Random random = new Random();
        List<User> list = new ArrayList<User>() {
            {
                for (int i = 0; i < 5; i++) {
                    add(new User(i, "李"+i, random.nextInt(50) + 50));
                }
            }
        };

        User[] users = new User[list.size()];
        list.toArray(users);
    /*    List<User> collect = list.stream().filter(user -> user.getAge() > 20).filter(user -> user.getSalary() > 60)
                .sorted((o1, o2) -> o1.getSalary().compareTo(o2.getSalary())).collect(Collectors.toList());
        for (User user : collect) {
            System.out.println(user);
        }*/


        Stream<User> stream = list.stream();
        System.out.println("split.................................");
        stream.forEach(info -> {
            System.out.println("过滤前: " + info.getName());
            if(info.getAge() >= 3){
                System.out.println(info.getName());
                list.remove(info);
                System.out.println(list);
            }
        });
        System.out.println("数据大小: " + list.size());
    }
}